<template>
  <PageWrapper contentFullHeight>
    <CollapseContainer title="表单基础示例">
      <BasicForm @register="register" @submit="handleSubmit" @reset="handleReset">
        <template #character>
          <heart-outlined />
        </template>
      </BasicForm>
    </CollapseContainer>
  </PageWrapper>
</template>
<script lang="ts" setup>
  import { ref } from 'vue';
  import { BasicForm, FormSchema, useForm } from '@/components/Form';
  import { CollapseContainer } from '@/components/Container';
  import { PageWrapper } from '@/components/Page';

  import { useMessage } from '@/hooks/web/useMessage';

  import { HeartOutlined } from '@ant-design/icons-vue';

  const { createMessage } = useMessage();

  // prettierrc-ignore
  // 字段信息
  const schemas: FormSchema[] = [
    {
      field: 'f1',
      component: 'Rate',
      label: '默认',
      colProps: {
        span: 8,
      },
    },
    {
      field: 'f2',
      component: 'Rate',
      label: '半星',
      colProps: {
        span: 8,
      },
      componentProps: {
        allowHalf: true,
      },
    },
    {
      field: 'f3',
      component: 'Rate',
      label: '三星',
      colProps: {
        span: 8,
      },
      componentProps: {
        allowHalf: true,
        count: 3,
      },
    },
  ];

  const [register] = useForm({
    labelWidth: 120,
    schemas,
    actionColOptions: { span: 24 },
    fieldMapToTime: [['fieldTime', ['startTime', 'endTime'], 'YYYY-MM']],
  });

  const keyword = ref<string>('');

  // 重置方法
  function handleReset() {
    keyword.value = '';
  }

  // 提交方法
  function handleSubmit(values: any) {
    console.log('values', values);
    createMessage.success('click search,values:' + JSON.stringify(values));
  }
</script>
